package com.qidian.mespro.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.qidian.mespro.mapper.ProcessMapper;

import com.qidian.mespro.service.ProcessService;
import com.qidianit.mes.pojo.Result;
import com.qidianit.mes.pojo.pro.Process;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Description:
 * @ Author: DuYaTao
 * @ Date: 2025/9/17 - 16:56
 */
@Service
public class ProcessServiceImpl implements ProcessService {

    @Autowired
    private ProcessMapper processMapper;

    @Override
    public Result<PageInfo<Process>> selectProcessList(Process process, int page, int size) {
        //开启分页
        PageHelper.startPage(page, size);
        List<Process> processeser = processMapper.selectAllProcess(process);
        return Result.success( new PageInfo<>(processeser));
    }

    @Override
    public Result<Process> addProcesser(Process process) {
        return processMapper.insertProcess(process) == 1 ? Result.success(process) : Result.error("新增失败");
    }

    @Override
    public Result<Process> selectProcesserByCode(String code) {
        return Result.success(processMapper.selectProcessByCode(code));
    }

    @Override
    public Result<Process> updateProcesser(Process process) {
        return processMapper.updateProcess(process) == 1 ? Result.success() : Result.error("修改失败");
    }

    @Override
    public Result<Process> deleteById(Long id) {
        return processMapper.deleteById(id) == 1 ? Result.success() : Result.error("删除失败");
    }

    @Override
    public Result<Process> batchDeleteByIds(Long[] ids) {
        return processMapper.batchDeleteByIds(ids) > 0 ? Result.success() : Result.error("批量删除失败");
    }
}
